Fix Ruby 3.3+ ARM64 segfault during shutdown#19
Open
phillip-haydon wants to merge 24 commits intomainfrom
Open
Fix Ruby 3.3+ ARM64 segfault during shutdown#19phillip-haydon wants to merge 24 commits intomainfrom
phillip-haydon wants to merge 24 commits intomainfrom
Conversation
- Add safe thread struct extraction using rb_thread_current() instead of rb_current_execution_context() which crashes on ARM64 due to TLS issues - Add version guards for Ruby 3.3+ M:N thread scheduler compatibility - Update debase-ruby_core_source dependency to support Ruby 3.3/3.4 - Add missing gems for Ruby 3.4+ (mutex_m, ostruct, csv) - Cache rb_rg_id_group for performance optimization Tested on Ruby 3.1.6, 3.3.7, and 3.4.2 without segfaults.
CmdrKeen
reviewed
Jan 1, 2026
CmdrKeen
reviewed
Jan 1, 2026
Address PR feedback - the < 5.0 constraints were overly aggressive since Ruby 4.0 was just released. Removed version ceiling to allow future Ruby versions to work without modification.
Amp-Thread-ID: https://ampcode.com/threads/T-019b981e-462b-751a-abec-cd26dcea6922 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019b981e-462b-751a-abec-cd26dcea6922 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019b981e-462b-751a-abec-cd26dcea6922 Co-authored-by: Amp <amp@ampcode.com>
…ee, bump to 1.1.15.pre2 - Fix old-style C function definitions () -> (void) across all source files - Fix use-after-free false positive in rax.c with temp variable pattern - Add -Wno-use-after-free to extconf.rb for remaining third-party rax patterns - Bump version to 1.1.15.pre2
- Update gem:native:darwin rbconfig paths for Ruby 3.0.7, 3.1.7, 3.2.9 - Replace Kernel#open with File.open - Add README.md documenting all 7 platform gems, build steps, release process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes segfault on Ruby 3.3+ ARM64 (Apple Silicon) during shutdown/finalization.
Problem
Ruby 3.3+ introduced the M:N thread scheduler where M Ruby threads are managed by N native threads. On ARM64,
rb_current_execution_context()uses TLS (Thread Local Storage) via__tls_get_addr(), which can segfault when TLS blocks are freed during Ruby shutdown.Solution
Inspired by Datadog dd-trace-rb, this PR:
rb_thread_current()(public API) +RTYPEDDATA_TYPE+rb_check_typeddata()for type-safe thread struct extractionRG_RUBY_VER_GE(3, 3)) to conditionally use the safe path on Ruby 3.3+Changes
ext/raygun/raygun_tracer.c: Addedrb_rg_thread_struct_from_object()with lazy-initialized type descriptor cacheext/raygun/raygun_tracer.h: Updatedrb_rg_get_current_thread_trace_context()macro for Ruby 3.3+ext/raygun/raygun_coercion.h: AddedRG_RUBY_VER_GE()version comparison macroext/raygun/extconf.rb: Improved error messages for missing headersraygun-apm.gemspec: Updateddebase-ruby_core_sourcedependency and Ruby version rangeGemfile: Added gems removed from Ruby 3.4+ defaults (mutex_m, ostruct, csv)Testing
Oracle Review
The changes were reviewed by the Oracle which confirmed: